//
//  CMDBPubDynamicParam.swift
//  CMDB
//
//  Created by 王磊 on 17/4/8.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBPubDynamicParam: CMDBBasicParamBean {
    
    var content: String = "" /*动态内容 */
    
    var imgs: String {
        
        guard upload_Images.count != 0 else {
            
            return ""
        }
        
        return CMDBPubDynamicParam.castImagesToString(upload_Images)
    }/* 动态照片，[{'width':100,'height':50,'url':'http://www.baidu.com'}] */
    var upload_Images: Array<CMDBImageParam> = []
}
extension CMDBPubDynamicParam {
    
    override func URLString() -> String {
        
        return CMDB_Http_Formal_Domain + "/app/trend/\(server_Version)/pubTrend?"
    }
}
extension CMDBPubDynamicParam {
    
    static func castImagesToString(arr: Array<CMDBImageParam>) -> String {
        
        let mutable = NSMutableArray()
        
        _ = arr.map({
            
            mutable.addObject($0.keyValues!)
            
        })
        
        let jsonData = try? NSJSONSerialization.dataWithJSONObject(mutable, options: .PrettyPrinted)
        
        guard let jsonTemp = jsonData else {
            
            return ""
        }
        let jsonStr = String(data: jsonTemp,encoding: NSUTF8StringEncoding)
        
        return jsonStr!
    }
}